public class MinorityVariants {

	int readMax = 20;
	int readMin = 9;
	double kmerMin = 0.0011;
	double kmerMax = 0.1;
	int mappingMax = 124;
	int mappingMin = 29;

	public int[] classifyReads(String[] reads) {
		int size = reads.length;
		int[] confidences = new int[size];
		for (int i = 0; i < size; i++) {
			confidences[i] = calculateConfidence(reads[i]);
		}
		return confidences;
	}

	public int calculateConfidence(String read) {
		String[] scores = read.split(" ");
		double readQuality = Integer.parseInt(scores[0]);
		if (readQuality > readMax) {
			readQuality = readMax;
		}
		if (readQuality < readMin) {
			readQuality = readMin;
		}
		readQuality = (Math.pow(9, readQuality / 13));

		double kmerAbundance = Float.parseFloat(scores[1]);
		if (kmerAbundance < kmerMin) {
			kmerAbundance = kmerMin;
		}
		if (kmerAbundance > kmerMax) {
			kmerAbundance = kmerMax;
		}

		// kmerAbundance = Math.pow(10000, kmerAbundance);

		double mappingScore = Integer.parseInt(scores[2]);
		if (mappingScore > mappingMax) {
			mappingScore = mappingMax;
		}
		if (mappingScore < mappingMin) {
			mappingScore = mappingMin;
		}
		mappingScore = (Math.pow(14, mappingScore / 128));

		long ret = Math.round(readQuality * kmerAbundance * mappingScore * 1000);
		if (ret > 1000000000) {
			ret = 1000000000;
		}
		return (int) ret;
	}

}
